target=double(imread('/Users/niexiaoyu/Desktop/RESEARCH10_Orthonormalized_Rednoise/MatLab文件/target_HO.png'));
% target(target<200)=0;
% target(target~=0)=255;
% load('/Users/niexiaoyu/Desktop/RESEARCH10_Orthonormalized_Rednoise/MatLab文件/TH_original.mat');
% target=a;
sgn=target;
sgn(sgn>0)=1;
bkg=target;
bkg(bkg<255)=1;
bkg(bkg>1)=0;
Npixel=5292;
a=zeros(5292); a(265)=0.050076; a(529)=0.099962; a(2646)=0.5; a(5292)=1;
Np=[]; xx=1; beta=[];
for i=0.05:0.05:1
    Npattern=round(Npixel*i);
    Np(xx)=Npattern;
    beta_real=Npattern/Npixel;
    beta(xx)=beta_real;
    xx=xx+1;
    a(Npattern)=beta_real;
end

%% Contrast to Noise Ratio
type={'gaussian_rednoise_ortho';'uniform_rednoise_ortho';'whitenoise_ortho';'whitenoise';'uniform_rednoise'};
for k=[1 3 4 5]
    name=type{k};
    j=1;
    for i=Np
        load(['/Users/niexiaoyu/Desktop/RESEARCH10_Orthonormalized_Rednoise/8.23 simulation_noise_OH/',name,'/',name,'_',num2str(a(i)),'.mat']);
        result=eval(['result_',name,'_',num2str(i),';']);
        bkg_result=result.*bkg;
        sgn_result=result.*sgn;
        eval(['CNR_',name,'_',num2str(i),'=(mean(sgn_result(sgn_result~=0))-mean(bkg_result(bkg_result~=0)))/(var(sgn_result(sgn_result~=0))+var(bkg_result(bkg_result~=0))).^0.5;']);
        eval(['CNR_',name,'(',num2str(j),')=CNR_',name,'_',num2str(i),';']);
        j=j+1;
    end
    subplot(2,2,1);
    point_type={'diamond-';'x-';'*-';'o-';'square-'};
    plot(beta,eval(['CNR_',name]),point_type{k},'LineWidth',2.5);
    hold on;
end
xlabel('\beta');
ylabel('CNR');
set(gca,'FontName','Times New Roman','FontSize',40,'LineWidth',1.5);
l=legend('OCGI','OWGI','WGI','PGI');
set(l,'FontName','Times New Roman','FontSize',30,'LineWidth',1.5);

%% Mean Square Error
type={'gaussian_rednoise_ortho';'uniform_rednoise_ortho';'whitenoise_ortho';'whitenoise';'uniform_rednoise'};
for k=[1 3 4 5]
    name=type{k};
    j=1;
    for i=Np
        load(['/Users/niexiaoyu/Desktop/RESEARCH10_Orthonormalized_Rednoise/8.23 simulation_noise_OH/',name,'/',name,'_',num2str(a(i)),'.mat']);
        result=eval(['result_',name,'_',num2str(i),';']);
        bkg_result=result.*bkg;
        sgn_result=result.*sgn;
        ref=sgn*mean(sgn_result(sgn_result~=0))+bkg*mean(bkg_result(bkg_result~=0));
        delta2=((result-ref)/mean(sgn_result(sgn_result~=0))).^2;
        eval(['MSE_',name,'_',num2str(i),'=mean(delta2(:));']);
        eval(['MSE_',name,'(',num2str(j),')=MSE_',name,'_',num2str(i),';']);
        j=j+1;
    end
    subplot(2,2,2);
    point_type={'diamond-';'x-';'*-';'o-';'square-'};
    plot(beta,eval(['MSE_',name]),point_type{k},'LineWidth',2.5);
    hold on;
end
xlabel('\beta');
ylabel('MSE');
set(gca,'FontName','Times New Roman','FontSize',40,'LineWidth',1.5);
l=legend('OCGI','OWGI','WGI','PGI');
set(l,'FontName','Times New Roman','FontSize',30,'LineWidth',1.5);


%% Peak Signal to Noise Ratio
type={'gaussian_rednoise_ortho';'uniform_rednoise_ortho';'whitenoise_ortho';'whitenoise';'uniform_rednoise'};
for k=[1 3 4 5]
    name=type{k};
    j=1;
    for i=Np
        load(['/Users/niexiaoyu/Desktop/RESEARCH10_Orthonormalized_Rednoise/8.23 simulation_noise_OH/',name,'/',name,'_',num2str(a(i)),'.mat']);
        result=eval(['result_',name,'_',num2str(i),';']);
        bkg_result=result.*bkg;
        sgn_result=result.*sgn;
        ref=sgn*mean(sgn_result(sgn_result~=0))+bkg*mean(bkg_result(bkg_result~=0));
        delta2=((result-ref)/mean(sgn_result(sgn_result~=0))).^2;
        eval(['PSNR_',name,'_',num2str(i),'=10*log10((2.^256-1).^2/mean(delta2(:)));']);
        eval(['PSNR_',name,'(',num2str(j),')=PSNR_',name,'_',num2str(i),';']);
        j=j+1;
    end
    subplot(2,2,3);
    point_type={'diamond-';'x-';'*-';'o-';'square-'};
    plot(beta,eval(['PSNR_',name]),point_type{k},'LineWidth',2.5);
    hold on;
end
xlabel('\beta');
ylabel('PSNR');
set(gca,'FontName','Times New Roman','FontSize',40,'LineWidth',1.5);
l=legend('OCGI','OWGI','WGI','PGI');
set(l,'FontName','Times New Roman','FontSize',30,'LineWidth',1.5);

%% Correlation Coefficient
type={'gaussian_rednoise_ortho';'uniform_rednoise_ortho';'whitenoise_ortho';'whitenoise';'uniform_rednoise'};
for k=[1 3 4 5]
    name=type{k};
    j=1;
    for i=Np
        load(['/Users/niexiaoyu/Desktop/RESEARCH10_Orthonormalized_Rednoise/8.23 simulation_noise_OH/',name,'/',name,'_',num2str(a(i)),'.mat']);
        result=eval(['result_',name,'_',num2str(i),';']);
        bkg_result=result.*bkg;
        sgn_result=result.*sgn;
        ref=sgn*mean(sgn_result(sgn_result~=0))+bkg*mean(bkg_result(bkg_result~=0));
        EE=result.*ref;
        CC=(mean(EE(:))-mean(result(:))*mean(ref(:)))/(var(result(:))*var(ref(:))).^0.5;
        eval(['CC_',name,'_',num2str(i),'=CC;']);
        eval(['CC_',name,'(',num2str(j),')=CC_',name,'_',num2str(i),';']);
        j=j+1;
    end
    subplot(2,2,4);
    point_type={'diamond-';'x-';'*-';'o-';'square-'};
    plot(beta,eval(['CC_',name]),point_type{k},'LineWidth',2.5);
    hold on;
end
xlabel('\beta');
ylabel('CC');
set(gca,'FontName','Times New Roman','FontSize',40,'LineWidth',1.5);
l=legend('OCGI','OWGI','WGI','PGI');
set(l,'FontName','Times New Roman','FontSize',30,'LineWidth',1.5);








